<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="card">
    <div class="card-header">
        <?php echo $payment_tips;?>
    </div>
    <div class="card-body ajax-body">
        <?php if (in_array($return['pay_api'], array(1,2))) {?>
        <div id="qrcode" class="d-flex justify-content-around my-3">

        </div>
        <?php } else {?>
        <form action="<?php echo url('plugin-buy', array('storeid' => $plugin['official']['storeid']), TRUE);?>" method="post" id="form">
            <div class="form-group">
                <?php echo lang('for_safe_input_official_login_password');?>
            </div>
            <div class="form-group input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"><i class="icon-lock"></i></span>
                </div>
                <input type="password" class="form-control" placeholder="<?php echo lang('password');?>" id="password" name="password">
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary btn-block col-md-4 mx-auto" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('submit');?></button>
            </div>
        </form>
        <?php }?>
    </div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script src="<?php echo admin_view_path();?>js/qrcode.min.js"></script>

<script ajax-eval="true">
    var pay_api = '<?php echo array_value($return, 'pay_api');?>';
    var qrcode = '<?php echo array_value($return, 'url');?>';
    var dir = '<?php echo $dir;?>';

    if(1 == pay_api) {
        $('.qrcode').html('<iframe runat="server" width="200px" height="210px" frameborder="no" allowtransparency="yes" scrolling="yes" src="' + qrcode + '" style="margin: 0 auto;"></iframe>');
    } else if(2 == pay_api) {
        let qrcode_img = kjua({text: qrcode});
        document.getElementById('qrcode').appendChild(qrcode_img);
    } else {
        var jform = $('#form');
        jform.on('submit', function() {
            jform.reset();
            var jthis = $(this);
            var jsubmit = jthis.find('#submit');
            jsubmit.button('loading');
            var postdata = jform.serializeObject();
            $.xpost(jform.attr('action'), postdata, function(code, message) {
                if(code == 0) {
                    jsubmit.button(message);
                    setTimeout(function() {
                        window.location.reload();
                    }, 1000);
                } else {
                    $.alert(message);
                    jsubmit.button('reset');
                }
            });
            return false;
        });
    }

    if(1 == pay_api || 2 == pay_api) {
        var times = 0;
        var t = setInterval(function() {
            if (++times > 60) {
                clearInterval(t);
                return false;
            }
            $.xget(xn.url('plugin-is_bought', {dir:dir}, true), function(code, message) {
                clearInterval(t); /*有返回则清除*/
                if(code == 0) {
                    window.location = xn.url('plugin-download', {dir:dir}, true);
                } else {
                    $.alert(message);
                }
            });
        }, 3000);
    }
</script>